home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 15 / macformat_15.iso / Shareware Internet / Ciencia / CFG 2.3 (Shareware) / µCinema Converter / apple events.c next >
Text File  |  1994-04-01  |  5KB  |  217 lines

  1. /*********************************************************************************
  2.     µCinema Converter 1.0
  3.     module: apple events.c
  4.     December 1992 - April 1994
  5.     by John A. Schlack
  6.     
  7.     Description:
  8.         This file contains routines for handling required apple events.
  9.     
  10.  *********************************************************************************/
  11.  
  12.  
  13. #include "constants.h"
  14.  
  15. #include "apple events.h"
  16. #include "PICS to QuickTime.h"
  17. #include "µCinema.h"
  18.  
  19.  
  20. /* -------------------------------------------------------------------------------- */
  21.  
  22.  
  23. enum AEventStatus { AE_NONE, AE_ODOC, AE_OTHER, AE_ERROR };
  24. static enum AEventStatus    aestatus;
  25.  
  26.  
  27. /* -------------------------------------------------------------------------------- */
  28.  
  29.  
  30. /* PRIVATE FUNCTION PROTOTYPES */
  31.  
  32. static pascal OSErr     handle_ODOC( AppleEvent * aevent, AppleEvent * reply, long refcon );
  33. static pascal OSErr     handle_QUIT( AppleEvent * aevent, AppleEvent * reply, long refcon );
  34. static pascal OSErr     handle_OAPP( AppleEvent * aevent, AppleEvent * reply, long refcon );
  35. static pascal OSErr     handle_PDOC( AppleEvent * aevent, AppleEvent * reply, long refcon );
  36. static OSErr            RequiredCheck( AppleEvent * aevent );
  37. static void                DoAEInstall( void );
  38. static void             high_level_process_events( void );
  39.  
  40.  
  41. /* -------------------------------------------------------------------------------- */
  42.  
  43.  
  44. static pascal OSErr handle_ODOC( AppleEvent * aevent, AppleEvent * reply, long refcon )
  45. {
  46.     OSErr                err;
  47.     AEDescList            docList;
  48.     FSSpec                spec;
  49.     long                items, i, num_errors;
  50.     AEKeyword            keyword;
  51.     DescType            typeCode;
  52.     Size                actualSize;
  53.     
  54.     err = AEGetParamDesc( aevent, keyDirectObject, typeAEList, &docList );
  55.     if (err) goto handle_ODOC_err;
  56.     
  57.     err = RequiredCheck( aevent );
  58.     if (err) goto handle_ODOC_err;
  59.     
  60.     err = AECountItems( &docList, &items );
  61.     if (err) goto handle_ODOC_err;
  62.     
  63.     for (i=1L; i<=items; i++)
  64.     {
  65.         err = AEGetNthPtr( &docList, i, typeFSS, &keyword, &typeCode, (Ptr) &spec,
  66.             sizeof( FSSpec ), &actualSize );
  67.         if (err) goto handle_ODOC_err;
  68.         picsToMovieBatch( &spec );
  69.     }
  70.     
  71.     aestatus = AE_ODOC;
  72.     return noErr;
  73.  
  74.  
  75. handle_ODOC_err:
  76.     aestatus = AE_ERROR;
  77.     return err;
  78. }
  79.  
  80.  
  81. /* -------------------------------------------------------------------------------- */
  82.  
  83.  
  84. static pascal OSErr handle_QUIT( AppleEvent * aevent, AppleEvent * reply, long refcon )
  85. {
  86.     OSErr    err;
  87.     
  88.     err = RequiredCheck( aevent );
  89.     if (err)
  90.     {
  91.         aestatus = AE_ERROR;
  92.         return err;
  93.     }
  94.     
  95.     installProgramStatus( PS_APP_DONE );
  96.     return noErr;
  97. }
  98.  
  99.  
  100. /* -------------------------------------------------------------------------------- */
  101.  
  102.  
  103. static pascal OSErr handle_OAPP( AppleEvent * aevent, AppleEvent * reply, long refcon )
  104. {
  105.     OSErr    err;
  106.     
  107.     err = RequiredCheck( aevent );
  108.     if (err)
  109.     {
  110.         aestatus = AE_ERROR;
  111.         return err;
  112.     }
  113.     
  114.     aestatus = AE_OTHER;
  115.     return noErr;
  116. }
  117.  
  118.  
  119. /* -------------------------------------------------------------------------------- */
  120.  
  121.  
  122. static pascal OSErr handle_PDOC( AppleEvent * aevent, AppleEvent * reply, long refcon )
  123. {
  124.     aestatus = AE_ERROR;
  125.     return errAEEventNotHandled;
  126. }
  127.  
  128.  
  129. /* -------------------------------------------------------------------------------- */
  130.  
  131.  
  132. static OSErr RequiredCheck( AppleEvent * aevent )
  133. {
  134.     OSErr        err;
  135.     DescType    typeCode;
  136.     Size        siz;
  137.     
  138.     err = AEGetAttributePtr( aevent, keyMissedKeywordAttr, typeWildCard, &typeCode,
  139.         0L, 0, &siz );
  140.     if (err == errAEDescNotFound) return noErr;
  141.     if (err == noErr) return errAEEventNotHandled;
  142.     return err;
  143. }
  144.  
  145.  
  146. /* -------------------------------------------------------------------------------- */
  147.  
  148.  
  149. static void DoAEInstall( void )
  150. {
  151.     AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments,
  152.         (EventHandlerProcPtr) handle_ODOC, 0, false );
  153.  
  154.     AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,
  155.         (EventHandlerProcPtr) handle_QUIT, 0, false );
  156.  
  157.     AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,
  158.         (EventHandlerProcPtr) handle_OAPP, 0, false );
  159.  
  160.     AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments,
  161.         (EventHandlerProcPtr) handle_PDOC, 0, false );
  162. }
  163.  
  164.  
  165. /* -------------------------------------------------------------------------------- */
  166.  
  167.  
  168. Boolean loadDragAndDrop( void )
  169. {
  170.     #define MAX_HIGH_EVT_WAIT    60    // 1.0 seconds
  171.     
  172.     long        end_tick, count;
  173.     CursHandle    waitCursorH;
  174.     
  175.     aestatus = AE_NONE;
  176.     DoAEInstall();
  177.     
  178.     // dump all events until we get to the high level events
  179.     FlushEvents( everyEvent, highLevelEventMask );
  180.     
  181.     end_tick = TickCount() + MAX_HIGH_EVT_WAIT;
  182.     count = 0L;
  183.     do
  184.     {
  185.         if (aestatus != AE_NONE) break;
  186.         if (count++ == 1L)
  187.         {
  188.             waitCursorH = GetCursor( watchCursor );
  189.             SetCursor( *waitCursorH );
  190.         }
  191.         high_level_process_events();
  192.     } while (TickCount() < end_tick);
  193.  
  194.     SetCursor( &arrow );
  195.     if (aestatus == AE_ERROR)
  196.         errorHandler( ERR_APPLE_EVENT );
  197.     return ((aestatus == AE_ODOC) ? true : false);
  198. }
  199.  
  200.  
  201. /* --------------------------------------------------------------------------------- */
  202.  
  203.  
  204. static void high_level_process_events( void )
  205. {
  206.     EventRecord    event;
  207.     Boolean        event_present;
  208.     
  209.     event_present = WaitNextEvent( highLevelEventMask, &event, 20L, 0L );
  210.     
  211.     if (event_present)
  212.     {
  213.         if ( event.what == kHighLevelEvent )
  214.             AEProcessAppleEvent( &event );
  215.     }
  216. }
  217.